#include <ros/ros.h>
#include <sensor_msgs/LaserScan.h>
#include <sensor_msgs/Imu.h>
#include <message_filters/subscriber.h>
#include "message_filters/synchronizer.h"
#include "message_filters/sync_policies/approximate_time.h"

void callback(const sensor_msgs::LaserScan::ConstPtr &scan_msg, const sensor_msgs::Imu::ConstPtr &imu_msg) {
    // 处理时间对齐后的激光雷达和IMU消息
}

int main(int argc, char **argv) {
    // 初始化ROS节点
    ros::init(argc, argv, "cre_time_sync_node");

    // 创建ROS句柄
    ros::NodeHandle nh;

    // 创建消息过滤器订阅激光雷达和IMU话题
    message_filters::Subscriber<sensor_msgs::LaserScan> scan_sub(nh, "/scan", 1);
    message_filters::Subscriber<sensor_msgs::Imu> imu_sub(nh, "/imu", 1);

    // 创建时间对齐器，设置时间同步阈值为0.1秒
    typedef message_filters::sync_policies::ApproximateTime<sensor_msgs::LaserScan, sensor_msgs::Imu> MySyncPolicy;
    message_filters::Synchronizer<MySyncPolicy> sync(MySyncPolicy(10), scan_sub, imu_sub);

    // 注册回调函数
    sync.registerCallback(boost::bind(&callback, _1, _2));

    // 进入ROS循环
    ros::spin();

    return 0;
}
